/*
 * TransiCast City Visions
 * (c) 2014 Joachim Pfeiffer
 * www.transicast.com
 */
package com.transicast.cityvisions;

import java.io.IOException;

import android.app.Activity;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;

import com.transicast.cityvisions.BuildConfig;
import com.transicast.cityvisions.R;
import com.metaio.sdk.MetaioDebug;
import com.metaio.tools.io.AssetsManager;

public class MainActivity extends Activity {
	private AssetsExtracter mTask;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setContentView(R.layout.main);

		MetaioDebug.enableLogging(BuildConfig.DEBUG);

		mTask = new AssetsExtracter();
		mTask.execute(0);
	}

	private class AssetsExtracter extends AsyncTask<Integer, Integer, Boolean> {

		@Override
		protected void onPreExecute() { }

		@Override
		protected Boolean doInBackground(Integer... params) {
			try {
				AssetsManager.extractAllAssets(getApplicationContext(), BuildConfig.DEBUG);
			} 
			catch (IOException e) {
				MetaioDebug.log(Log.ERROR, "Error extracting assets: "+e.getMessage());
				MetaioDebug.printStackTrace(Log.ERROR, e);
				return false;
			}
			return true;
		}

		@Override
		protected void onPostExecute(Boolean result) {
			Intent intent = new Intent(getApplicationContext(), ARView.class);
			startActivity(intent);
			finish();
	    }
	}
}
